package com.hgl.servlet.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.extra.servlet.ServletUtil;

import com.hgl.entity.Hgl;
import com.hgl.service.HglService;
import com.hgl.service.impl.HglServiceImpl;


@WebServlet("/admin/user-update.let")
public class UserUpdateServlet extends HttpServlet {
	
	private HglService hglService =  new HglServiceImpl();

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		//设置请求的字符集编码，默认：iso-8859-1,本质设置的是请求正文的字符集编码.post的字符集编码

		Hgl hgl = new Hgl();
		hgl.setHglId(Integer.valueOf( request.getParameter("hglId")));
		ServletUtil.fillBean(request, hgl, true);
		
		
		System.out.println(hgl);
		
		//调用业务逻辑的接口
		
		try{
			hglService.update(hgl);
			request.setAttribute("msg", "修改用户成功");
			request.setAttribute("href","admin/news-list.let");
		}catch(Exception ex){
			ex.printStackTrace();//记调试日志
			request.setAttribute("error", "修改用户失败:"+ex.getMessage());
		}
		//跳转到视图
		request.getRequestDispatcher("/admin/msg.jsp").forward(request, response);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	 doPost(req, resp);
	}
}
